package maiyatian.videolive.adapter.main;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

import maiyatian.videolive.IClickListener;
import maiyatian.videolive.R;
import maiyatian.videolive.bean.LiveBean;

/**
 * Created by 王中阳 on 2016/5/10.
 */
public class SeebackAdapter extends BaseAdapter {
    public static final String TAG = "SeebackAdapter";
    private Context mycontext;
    private List<LiveBean> datas;
    private IClickListener mCallbak;

    public SeebackAdapter(Context mycontext, List<LiveBean> datas, IClickListener mCallbak) {
        this.datas = datas;
        this.mycontext = mycontext;
        this.mCallbak = mCallbak;
    }

    public void setDatas(List<LiveBean> datas) {
        this.datas = datas;
        notifyDataSetChanged();
        Log.e(TAG, "setDatas: "+datas.size());
    }

    @Override
    public int getCount() {
        if (datas != null) {
            return datas.size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        LiveBean bean = null;
        bean = datas.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(mycontext).inflate(R.layout.item_hot, parent, false);
            AutoUtils.autoSize(convertView);
        }
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallbak.onItemClicked(position);
            }
        });
        return convertView;
    }
}
